package at.spengergasse.web.servlet.bestellen;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import at.spengergasse.dao.BestellenDao;
import at.spengergasse.dao.ProdukteDao;
import at.spengergasse.dao.RechnungDao;
import at.spengergasse.dao.derby.BestellenDaoDerbyImpl;
import at.spengergasse.dao.derby.ProdukteDaoDerbyImpl;
import at.spengergasse.dao.derby.RechnungDaoDerbyImpl;
import at.spengergasse.web.EntryPointURLEnum;
import at.spengergasse.web.servlet.LoginServlet;
import at.spengergasse.web.servlet.produkte.ProdukteFieldNames;

@SuppressWarnings("serial")
public class AbstractBestellenServlet extends LoginServlet
{
	// protected static BestellenDao bestellenDAO = new BestellenDaoDerbyImpl();
	protected static ProdukteDao produkteDAO = new ProdukteDaoDerbyImpl();
	protected static RechnungDao rechnungDAO = new RechnungDaoDerbyImpl();
	protected static BestellenDao bestellDAO = new BestellenDaoDerbyImpl();

	public AbstractBestellenServlet() throws Exception
	{
		super();

	}

	protected Long checkProduktIdParam(HttpServletRequest req,
			HttpServletResponse resp) throws ServletException, IOException
	{
		Long bestellId = null;
		try
		{
			bestellId = Long.valueOf(req.getParameter(ProdukteFieldNames.ID));
		} catch (Exception e)
		{
			log.warn("problems with given customerId!", e);
		}

		//
		return bestellId;
	}

	protected void redirectToProduktBestellList(HttpServletRequest req,
			HttpServletResponse resp) throws ServletException, IOException
	{
		redirectToProduktBestellList(req, resp, null);
	}

	protected void redirectToProduktBestellList(HttpServletRequest req,
			HttpServletResponse resp, String errorMessage)
			throws ServletException, IOException
	{
		if (errorMessage != null)
		{
			req.getSession(true).setAttribute("errorMessage", errorMessage);
		}
		resp.sendRedirect(EntryPointURLEnum.PRODUKT_BESTELL_LIST.getUrl());
	}

}
